//
//  TSRTLManage.swift
//  Pods
//
//  Created by 100Years on 2025/6/17.
//

public class TSRTLManage {
    public static func setUpInit () {
        if kIsRTL {
            UIView.appearance().semanticContentAttribute = UISemanticContentAttribute.forceRightToLeft
        }else{
            UIView.appearance().semanticContentAttribute = UISemanticContentAttribute.forceLeftToRight
        }
    }
    
    public static func isRTL () -> Bool {
        if let provider = LocalizationManager.sharedProvider {
            return provider.isArabic() && TSConfig.isArabicSupported()
        }
        return TSConfig.appLanguage.hasPrefix("ar") && TSConfig.isArabicSupported()
    }
}

public var kIsRTL: Bool {
    return TSRTLManage.isRTL()
}


public extension UIImage {
    public var mirrored: UIImage {
        guard kIsRTL else {
            return self
        }
        return imageFlippedForRightToLeftLayoutDirection()
    }
    
}


public protocol LocalizationProvider {
    func localizedString(for key: String) -> String
    func isArabic() -> Bool
}

public class LocalizationManager {
    public static var sharedProvider: LocalizationProvider?
}

public extension String {
    var localized:String {
        if let provider = LocalizationManager.sharedProvider {
            return provider.localizedString(for: self)
        }
        return NSLocalizedString(self, comment: self)
    }
}
